import Vue from "vue";
import Router from "vue-router";
import { staticRoutes, routerMap } from "./routeMap";
Vue.use(Router);

// hack router push callback
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject);
  }
  return originalPush.call(this, location).catch((err) => err);
};
const createRouter = () =>
  new Router({
    // base: process.env.BASE_URL,
    mode: "history",
    routes: routerMap,
    // routes: staticRoutes,
  });
const router = createRouter();
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // the relevant part
}
export default router;
